using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class BaseMassSendElement : ContentControl
	{
		private const string TAG = "BaseMassSendElement";
		private MassMsgItemTitle massSendItemTitle;
		private HyperlinkButton btnOneMoreMsg;
		private StackPanel stackContainer;
		private Button btnContent;
		private RightChatContent ChatContentCtrl;
		private MassMsg massMsg_0;
		private MenuItem delItem;
		private ContextMenu menu;
		public static DependencyProperty ContentTypeProperty = DependencyProperty.Register("ContentType", typeof(string), typeof(BaseMassSendElement), new PropertyMetadata(null, new PropertyChangedCallback(BaseMassSendElement.OnItemPropertyChanged)));
		protected bool mIsGlittleing;
		public string ContentType
		{
			get
			{
				return (string)base.GetValue(BaseMassSendElement.ContentTypeProperty);
			}
			set
			{
				base.SetValue(BaseMassSendElement.ContentTypeProperty, value);
			}
		}
		public bool IsGlittleing
		{
			get
			{
				return this.mIsGlittleing;
			}
			set
			{
				if (value == this.mIsGlittleing)
				{
					return;
				}
				this.mIsGlittleing = value;
				this.GlittleingChange(value);
			}
		}
		public BaseMassSendElement()
		{
			base.add_Loaded(new RoutedEventHandler(this.BaseMassSendElement_Loaded));
		}
		private void BaseMassSendElement_Loaded(object sender, RoutedEventArgs e)
		{
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.massSendItemTitle = (base.GetTemplateChild("massSendTitle") as MassMsgItemTitle);
			this.btnOneMoreMsg = (base.GetTemplateChild("btnOneMoreMsg") as HyperlinkButton);
			this.stackContainer = (base.GetTemplateChild("StackContainer") as StackPanel);
			this.btnContent = (base.GetTemplateChild("ContentButton") as Button);
			this.ChatContentCtrl = (base.GetTemplateChild("ChatContentCtrl") as RightChatContent);
			if (this.massSendItemTitle != null)
			{
				this.InitTitle();
			}
			if (this.btnOneMoreMsg != null)
			{
				this.btnOneMoreMsg.add_Click(new RoutedEventHandler(this.btnOneMoreMsg_Click));
				this.btnOneMoreMsg.set_Content(strings.MassSend_ReadMessage_SendAgain);
				this.btnOneMoreMsg.set_Foreground(R.theme.COMMON_BRUSH);
			}
			if (this.stackContainer != null)
			{
				this.CreatMenu();
			}
			if (this.ChatContentCtrl != null)
			{
				this.ChatContentCtrl.add_Click(new RoutedEventHandler(this.VoiceItem_Click));
			}
			if (this.btnContent != null)
			{
				this.btnContent.add_Click(new RoutedEventHandler(this.ImageItem_Click));
			}
		}
		private void ImageItem_Click(object sender, RoutedEventArgs e)
		{
			if (this.massMsg_0 == null)
			{
				return;
			}
			if (this.massMsg_0.IsImage())
			{
				ToolFunction.GotoPageForUserControl("/Source/UI/Chat/ImageView.xaml", new object[]
				{
					this.massMsg_0
				}, false);
			}
		}
		private void VoiceItem_Click(object sender, RoutedEventArgs e)
		{
			if (this.massMsg_0 == null)
			{
				return;
			}
			if (this.massMsg_0.IsVoice())
			{
				BasePage topPage = PageManager.getInstance().GetTopPage();
				if (!(topPage is MessagesListPage))
				{
					return;
				}
				MessagesListPage messagesListPage = topPage as MessagesListPage;
				messagesListPage.VoiceItemClick(this.massMsg_0.strFileName, this as MassSendVoiceItem);
			}
		}
		private void btnOneMoreMsg_Click(object sender, RoutedEventArgs e)
		{
			ToolFunction.GotoPageForUserControl("/Source/Plugin/MassSend/UI/SendMessagePage.xaml", new object[]
			{
				this.massMsg_0.strUserNameList,
				this.massMsg_0.nUserCount,
				true
			}, false);
		}
		private void InitTitle()
		{
			if (this.massMsg_0 == null)
			{
				return;
			}
			this.massSendItemTitle.listCount = this.massMsg_0.nUserCount.ToString();
			string text = "";
			string[] array = this.massMsg_0.strUserNameList.Split(new char[]
			{
				';'
			});
			for (int i = 0; i < array.Length - 1; i++)
			{
				text += ContactHelper.getDisplayName(array[i], null);
				text += ", ";
			}
			text += ContactHelper.getDisplayName(array[array.Length - 1], null);
			this.massSendItemTitle.listNames = text;
		}
		public virtual void SetMassMsg(MassMsg Msg)
		{
			this.massMsg_0 = Msg;
		}
		public void CreatMenu()
		{
			this.menu = new ContextMenu();
			this.menu.set_Width(200.0);
			this.menu.set_Background(R.theme.CONTEXTMENU_BACKGROUND_BRUSH);
			this.menu.IsZoomEnabled = true;
			this.delItem = new MenuItem();
			this.delItem.Header = strings.ChatItemDelete;
			this.delItem.set_Foreground(R.theme.CONTEXTMENU_FOREGROUND_BRUSH);
			this.delItem.Click += new RoutedEventHandler(this.delItem_Click);
			this.menu.get_Items().Add(this.delItem);
			ContextMenuService.SetContextMenu(this.stackContainer, this.menu);
		}
		private void delItem_Click(object sender, RoutedEventArgs e)
		{
			if (this.massMsg_0 == null)
			{
				return;
			}
			if (this.massMsg_0 is MassSendTimeMsg)
			{
				return;
			}
			MassMsgMgr.deleteMassMsg(this.massMsg_0);
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			(dependencyObject_0 as BaseMassSendElement).OnContentTypePropertyChanged(dependencyPropertyChangedEventArgs_0);
		}
		private void OnContentTypePropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
		}
		public virtual void SetMsgContent(string msgContent)
		{
		}
		public virtual void SetImgSrc(string ImgSrc)
		{
		}
		public virtual void SetVoiceLen(int voiceLen)
		{
		}
		protected virtual void GlittleingChange(bool newValue)
		{
		}
	}
}
